home *** CD-ROM | disk | FTP | other *** search
/ Libris Britannia 4 / science library(b).zip / science library(b) / DJGPP / QDDVX102.ZIP / contrib / dvx / docs / sockets.doc < prev    next >
Text File  |  1993-07-15  |  35KB  |  1,466 lines

  1. Socket Library programming reference
  2. ------------------------------------
  3.  
  4. In order for applications to communicate with each other, whether 
  5. on the same machine or different machine across a network, the 
  6. Berkeley Socket Interface was chosen as the means to accomplish 
  7. this in the DESQview/X environment.
  8.  
  9. The reasons for this are clear. The Berkeley Socket Interface is 
  10. the standard by which other X Window systems and UNIX systems use 
  11. to communicate. In addition, it is network independent - in fact, 
  12. a network need not be present on a standalone system.
  13.  
  14. DESQview/X the Berkeley Socket Interface 4.3, or BSD 4.3. This 
  15. release includes 2 different types of communication - stream 
  16. (TCP) and datagram (UDP). DESQview/X, through its BSD 4.3 
  17. routines, supports both of these types.
  18.  
  19. DESQview/X supplies both the include files necessary to compile 
  20. an application that uses BSD 4.3 as well as a socket library that 
  21. performs the low level functions. The include files needed are 
  22. specified in each function's synopsis. The socket library is 
  23. included in the DESQview/X System Library which should be linked 
  24. into your application.
  25.  
  26. Since the Berkeley Socket Interface is a well-defined (and 
  27. expansive) interface, this document does not attempt to teach a 
  28. user how to use BSD 4.3 Sockets - there is plenty of material 
  29. that does this already. Instead, each of the BSD 4.3 Socket 
  30. routines that are supported in DESQview/X will now be listed in 
  31. reference form.
  32.  
  33.  
  34. Supported BSD 4.3 Socket Routines
  35. ---------------------------------
  36.  
  37.  
  38. sethostent()
  39. ************
  40.  
  41. Synopsis
  42. --------
  43. #include <sys/types.h>
  44. #include <sys/socket.h>
  45. #include <netdb.h>
  46.  
  47. void sethostent(void);
  48.  
  49. Description
  50. -----------
  51. sethostent opens and rewinds the local HOSTS file.  This call is 
  52. primarily useful for resetting the HOSTS file to the first entry 
  53. in preparation for calls to gethostent.
  54.  
  55.  
  56.  
  57. See Also
  58. --------
  59. gethostent, gethostbyname, gethostbyaddr, endhostent
  60.  
  61.  
  62. gethostent()
  63. ************
  64.  
  65. Synopsis
  66. --------
  67. #include <sys/types.h>
  68. #include <sys/socket.h>
  69. #include <netdb.h>
  70.  
  71. struct hostent *gethostent(void);
  72.  
  73. Description
  74. -----------
  75.  
  76. gethostent reads the next entry in the local HOSTS file, opening 
  77. the file if necessary.  The return value is a pointer to an 
  78. structure containing the broken-out fields of a line from the 
  79. HOSTS file.  The structure definition is as follows:
  80.  
  81. struct hostent
  82. {
  83.    char *h_name;
  84.    char **h_aliases;
  85.    int  h_addrtype;
  86.    int  h_length;
  87.    char **h_addr_list;
  88. };
  89.  
  90. h_name        Official name of the host.
  91. h_aliases     A NULL terminated array of alternate names for the 
  92.               host.
  93. h_addrtype    The type of address being returned.  Always 
  94.               AF_INET;
  95. h_length      The length, in bytes, of the address.
  96. h_addr_list   A pointer to a list of network addresses for the 
  97.               named host.
  98.  
  99. Notes
  100. -----
  101. A macro is provided as follows to convert the BSD4.3 format 
  102. h_addr_list element to a BSD4.2 format:
  103.  
  104. #define h_addr    h_addr_list[0]
  105.  
  106. Return Values
  107. -------------
  108. gethostent returns NULL on failure or EOF.
  109.  
  110. See Also
  111. --------
  112. sethostent, gethostbyname, gethostbyaddr, endhostent
  113.  
  114.  
  115. endhostent()
  116. ************
  117.  
  118. Synopsis
  119. --------
  120. #include <sys/types.h>
  121. #include <sys/socket.h>
  122. #include <netdb.h>
  123.  
  124. void endhostent(void);
  125.  
  126. Description
  127. -----------
  128. Closes the local host file.
  129.  
  130.  
  131. See Also
  132. --------
  133. sethostent, gethostent, gethostbyname, gethostbyaddr
  134.  
  135.  
  136. gethostbyaddr()
  137. ***************
  138.  
  139. Synopsis
  140. --------
  141. #include <sys/types.h>
  142. #include <sys/socket.h>
  143. #include <netdb.h>
  144.  
  145. struct hostent *gethostbyaddr(long *addr,int addrLen,int af);
  146.  
  147. Description
  148. -----------
  149. Searches the local HOSTS file sequentially until an entry is 
  150. found with an h_addr_list entry corresponding to the address 
  151. pointed to by the 'addr' parameter.
  152.  
  153. Return Values
  154. -------------
  155. gethostbyaddr returns NULL on failure.
  156.  
  157. Notes
  158. -----
  159. The hostent structure is defined in the description of the 
  160. gethostent call.
  161.  
  162. See Also
  163. --------
  164. sethostent, gethostent, gethostbyname, endhostent
  165.  
  166.  
  167. gethostbyname()
  168. ***************
  169.  
  170. Synopsis
  171. --------
  172. #include <sys/types.h>
  173. #include <sys/socket.h>
  174. #include <netdb.h>
  175.  
  176. struct hostent *gethostbyname(char *name);
  177.  
  178. Description
  179. -----------
  180. Searches the local HOSTS file sequentially until an entry is 
  181. found with an h_name that corresponds to the 'name' parameter.
  182.  
  183. Return Values
  184. -------------
  185. gethostbyname returns NULL on failure.
  186.  
  187. See Also
  188. --------
  189. sethostent, gethostent, gethostbyaddr, endhostent
  190.  
  191.  
  192. gethostname()
  193. *************
  194.  
  195. Synopsis
  196. --------
  197.  
  198. #include <sys/types.h>
  199. #include <sys/socket.h>
  200. #include <netdb.h>
  201.  
  202. int gethostname(char *name,int nameLen);
  203.  
  204. Description
  205. -----------
  206. gethostname retrieves the name of the local host.  The 'name' 
  207. parameter is a buffer of maximum size designated by the 'nameLen' 
  208. parameter.  The buffer will be filled with a null-terminated 
  209. string unless insufficient space is available.
  210.  
  211. Return Values
  212. -------------
  213. gethostname returns bytes filled on success, -1 on failure.
  214.  
  215.  
  216. setservent()
  217. ************
  218.  
  219. Synopsis
  220. --------
  221. #include <netdb.h>
  222.  
  223. void setservent(void);
  224.  
  225. Description
  226. -----------
  227. setservent opens and rewinds the local SERVICES file.  This call 
  228. is primarily useful for resetting the SERVICES file to the first 
  229. entry in preparation for calls to getservent.
  230.  
  231. See Also
  232. --------
  233. endservent, getservent, getservbyport, getservbyname
  234.  
  235.  
  236. getservent()
  237. ************
  238.  
  239. Synopsis
  240. --------
  241. #include <netdb.h>
  242.  
  243. struct servent *getservent(void);
  244.  
  245. Description
  246. -----------
  247. getservent reads the next entry in the local SERVICES file, 
  248. opening the file if necessary.  The return value is a pointer to 
  249. an structure containing the broken-out fields of a line from the 
  250. SERVICES file.  The structure definition is as follows:
  251.  
  252. struct servent
  253. {
  254.    char *s_name;
  255.    char **s_aliases;
  256.    int  s_port;
  257.    char *s_proto;
  258. };
  259.  
  260.  
  261. s_name        The official name of the service.
  262. s_aliases     A NULL terminated list of alternate names for the 
  263.               service.
  264. s_port        The port number which the service uses. Port 
  265.               numbers are returned in network short byte order.
  266. s_proto       The name of the protocol to use when contacting the 
  267.               service.
  268.  
  269. Return Values
  270. -------------
  271. getservent returns NULL on failure or EOF.
  272.  
  273. See Also
  274. --------
  275. setservent, getservbyname, getservbyport, endservent
  276.  
  277.  
  278. endservent()
  279. ************
  280.  
  281. Synopsis
  282. --------
  283. #include <netdb.h>
  284.  
  285. void endservent(void);
  286.  
  287. Description
  288. -----------
  289. endservent closes the local SERVICES file.
  290.  
  291. See Also
  292. --------
  293. setservent, getservent, getservbyport, getservbyname 
  294.  
  295.  
  296. getservbyname()
  297. ***************
  298.  
  299. Synopsis
  300. --------
  301. #include <netdb.h>
  302.  
  303. struct servent *getservbyname(char *name,char *proto);
  304.  
  305. Description
  306. -----------
  307. getservbyname searches the local SERVICES file sequentially until 
  308. an entry with the s_name field matching the 'name' parameter is 
  309. found.  If a non-NULL 'proto' parameter is specified, the search 
  310. will also include a match of the s_proto field with the 'proto' 
  311. parameter.
  312.  
  313. Notes
  314. -----
  315. The servent structure is defined in the description of the 
  316. getservent call.
  317.  
  318. Return Values
  319. -------------
  320. getservbyname returns NULL on failure.
  321.  
  322. See Also
  323. --------
  324. setservent, getservent, getservbyport, endservent
  325.  
  326.  
  327. getservbyport()
  328. ***************
  329.  
  330. Synopsis
  331. --------
  332. #include <netdb.h>
  333.  
  334. struct servent *getservbyport(int port,char *proto);
  335.  
  336. Description
  337. -----------
  338. getservbyport searches the local SERVICES file sequentially until 
  339. an entry with an s_port matching the 'port' parameter is found.  
  340. If a a non-NULL 'proto' parameter is specified, the search will 
  341. also include a match of the s_proto field with the 'proto' 
  342. parameter.
  343.  
  344. Notes
  345. -----
  346. The servent structure is defined in the description of the 
  347. getservent call.
  348.  
  349. Return Values
  350. -------------
  351. getservbyport returns NULL on failure.
  352.  
  353. See Also
  354. --------
  355. setservent, getservent, getservbyname, endservent
  356.  
  357.  
  358. setprotoent()
  359. *************
  360.  
  361. Synopsis
  362. --------
  363. #include <netdb.h>
  364.  
  365. void setprotoent(void);
  366.  
  367. Description
  368. -----------
  369. setprotoent opens and rewinds the local PROTOCOLS file.  This 
  370. call is primarily useful for resetting the PROTOCOLS file to the 
  371. first entry in preparation for calls to getprotoent.
  372.  
  373. See Also
  374. --------
  375. getprotoent, getprotobyname, getprotobynumber, endprotoent
  376.  
  377.  
  378. getprotoent()
  379. *************
  380.  
  381. Synopsis
  382. --------
  383. #include <netdb.h>
  384.  
  385. struct protoent *getprotoent(void);
  386.  
  387. Description
  388. -----------
  389. getprotoent reads the next entry in the local PROTOCOLS file, 
  390. opening the file if necessary.  The return value is a pointer to 
  391. an structure containing the broken-out fields of a line from the 
  392. PROTOCOLS file.  The structure definition is as follows:
  393.  
  394. struct protoent
  395. {
  396.    char *p_name;
  397.    char **p_aliases;
  398.    int  p_proto;
  399. };
  400.  
  401. p_name     The official name of the protocol.
  402. p_aliases  A zero terminated list of alternate names for the protocol.
  403. p_proto    The protocol number.
  404.  
  405. Return Values
  406. -------------
  407. getprotoent returns NULL on failure or EOF.
  408.  
  409. See Also
  410. --------
  411. setprotoent, getprotobyname, getprotobynumber, endprotoent
  412.  
  413.  
  414. endprotoent()
  415. *************
  416.  
  417. Synopsis
  418. --------
  419. #include <netdb.h>
  420.  
  421. void endprotoent(void);
  422.  
  423. Description
  424. -----------
  425. endprotoent closes the local PROTOCOLS file.
  426.  
  427. See Also
  428. --------
  429. setprotoent, getprotoent, getprotobyname, getprotobynumber
  430.  
  431.  
  432. getprotobyname()
  433. ****************
  434.  
  435. Synopsis
  436. --------
  437. #include <netdb.h>
  438.  
  439. struct protoent *getprotobyname(char *name);
  440.  
  441. Description
  442. -----------
  443. getprotobyname searches the local PROTOCOLS file sequentially 
  444. until an entry is found with a p_name that matches the 'name' 
  445. parameter.
  446.  
  447. Notes
  448. -----
  449. The protoent structure is defined in the description of the 
  450. getprotoent call.
  451.  
  452. Return Values
  453. -------------
  454. getprotobyname returns NULL on failure.
  455.  
  456. See Also
  457. --------
  458. setprotoent, getprotoent, getprotobynumber, endprotoent
  459.  
  460.  
  461. getprotobynumber()
  462. ******************
  463.  
  464. Synopsis
  465. --------
  466. #include <netdb.h>
  467.  
  468. struct protoent *getprotobynumber(int proto);
  469.  
  470. Description
  471. -----------
  472. getprotobynumber searches the local PROTOCOLS file sequentially 
  473. until an entry is found with a p_proto that matches the 'proto' 
  474. parameter.
  475.  
  476. Notes
  477. -----
  478. The protoent structure is defined in the description of the 
  479. getprotoent call.
  480.  
  481. Return Values
  482. -------------
  483. getprotobynumber returns NULL on failure.
  484.  
  485. See Also
  486. --------
  487. setprotoent, getprotoent, getprotobyname, endprotoent socket
  488.  
  489. Synopsis
  490. --------
  491. #include <sys/types.h>
  492. #include <sys/socket.h>
  493.  
  494. int socket(int af,int type,int protocol);
  495.  
  496. Description
  497. -----------
  498. socket opens an endpoint for network communication.  The af 
  499. parameter specifies the address family desired for the socket.  
  500. The following address families are supported:
  501.  
  502. AF_INET       Internet addressing family
  503.  
  504. AF_UNIX       Local (file-type) addressing family
  505.  
  506. The 'type' parameter specifies the method of I/O that will be 
  507. available to the socket.  SOCK_STREAM and SOCK_DGRAM are 
  508. supported.
  509.  
  510. SOCK_STREAM type sockets provide connection oriented, stream 
  511. communications.  Similar to pipes, full duplex, reliable and 
  512. sequenced delivery is guarenteed.  In order for I/O to occur, the 
  513. socket must be in a connected state.  Data transfer is 
  514. accomplished by way of the recv and send calls, and both blocking 
  515. and non-blocking modes are supported.
  516.  
  517. SOCK_DGRAM type sockets provide connectionless, datagram (fixed 
  518. length) communications.  There is no guarentee of reliablity or 
  519. sequencing. SOCK_DGRAM sockets need not be in a connected state 
  520. in order to transmit or receive data.  Data transfer is 
  521. accomplished by way of the recvfrom and sendto calls, and both 
  522. blocking and non-blocking modes are supported.
  523.  
  524. The 'protocol' parameter is ignored at this time.
  525.  
  526. Return Values
  527. -------------
  528. socket returns a non-negative descriptor on success, -1 on 
  529. failure (errno as described below).
  530.  
  531. Errors
  532. ------
  533. EAFNOSUPPORT     The address family specified is not supported.
  534. EPROTOTYPE       The protocol specified is not supported.
  535. ESOCKTNOSUPPORT  The type specified is not SOCK_STREAM or 
  536.                  SOCK_DGRAM
  537. ENOBUFS          The network has exhausted it's resources.
  538.  
  539.  
  540. See Also
  541. --------
  542. accept, bind, connect,  getsockname, ioctl, listen, recv, select, 
  543. send, shutdown, so_close
  544.  
  545.  
  546. so_close()
  547. **********
  548.  
  549. Synopsis
  550. --------
  551. #include <sys/types.h>
  552. #include <sys/socket.h>
  553.  
  554. int so_close(int s);
  555.  
  556. Description
  557. -----------
  558. Closes and frees the socket descriptor referenced by 's'.  If the 
  559. socket is of type SOCK_STREAM and in a connected state, the 
  560. connection is closed, and the remote peer is notified.  If the 
  561. socket is of type SOCK_STREAM and in a listening state, any 
  562. connections available for acceptance will be lost.
  563.  
  564. Return Values
  565. -------------
  566. so_close returns 0 on success, -1 on failure (errno as described 
  567. below).
  568.  
  569. Errors
  570. ------
  571. ENOTSOCK      The specified descriptor was invalid. shutdown
  572.  
  573. Synopsis
  574. --------
  575. #include <sys/types.h>
  576. #include <sys\socket.h>
  577.  
  578. int shutdown(int s,int how);
  579.  
  580. Description
  581. -----------
  582. Causes all or part of a full-duplex connection on the socket 
  583. associated with s to be shut down.  If how is SD_RECV, then 
  584. further receives will be disallowed.  If how is SD_SEND then 
  585. further sends will be disallowed.  If how is SD_SENDRECV then 
  586. both further sends and receives will be disallowed.
  587.  
  588. Return Values
  589. -------------
  590. shutdown returns 0 on success, -1 on failure (errno as described 
  591. below).
  592.  
  593. Errors
  594. ------
  595. ENOTSOCK      Invalid descriptor.
  596. ENOTCONN      Socket is not connected and is not a datagram 
  597.               socket.
  598.  
  599.  
  600. bind()
  601. ******
  602.  
  603. Synopsis
  604. --------
  605. #include <sys/types.h>
  606. #include <sys/socket.h>
  607.  
  608. int bind(int s,struct sockaddr_in *addr,int addrLen);
  609.  
  610. Description
  611. -----------
  612. Assigns a name to the unnamed socket referenced by 's'.  The name 
  613. bound to the socket is specified by the 'addr' parameter.
  614.  
  615. Return Values
  616. -------------
  617. bind returns 0 on success, -1  on failure (errno as described 
  618. below).
  619.  
  620. Errors
  621. ------
  622. ENOTSOCK      Invalid descriptor.
  623. EAFNOSUPPORT  Invalid address family.
  624. EINVAL        Socket is already bound.
  625. EADDRINUSE    A socket is already bound to the address on the 
  626.               local host.
  627.  
  628.  
  629. getsockname()
  630. *************
  631.  
  632. Synopsis
  633. --------
  634. #include <sys/types.h>
  635. #include <sys\socket.h>
  636.  
  637. int getsockname(int s,struct sockaddr_in *name,int *nameLen);
  638.  
  639. Description
  640. -----------
  641. getsockname returns the name associated with socket s, assigned 
  642. by a previous call to bind.  The value pointed to by namelen 
  643. should be initialized to the size of the buffer pointed to by 
  644. 'name'.  The name of the socket will be placed into the buffer 
  645. pointed to by the 'name' parameter and the value pointed to by 
  646. the 'namelen' parameter will be updated to the actual size of the 
  647. name returned.
  648.  
  649. Return Values
  650. -------------
  651. getsockname returns 0 on success, -1 on failure (errno as 
  652. described below).
  653.  
  654. Errors
  655. ------
  656. ENOTSOCK      Invalid descriptor.
  657. EINVAL        Socket is not bound.
  658.  
  659.  
  660. ioctl()
  661. *******
  662.  
  663. Synopsis
  664. --------
  665. #include <sys/types.h>
  666. #include <sys\socket.h>
  667.  
  668. int ioctl(int s,int req,char *argp);
  669.  
  670. Description
  671. -----------
  672. Modifies the I/O strategy on the socket specified by 's' to the 
  673. strategy indicated by 'req' and value specified by 'argp'.  For 
  674. example, modification of a socket to a non-blocking I/O strategy 
  675. would entail a call as follows:
  676.  
  677.     nonBlocking = 1l;
  678.     ioctl(s, FIONBIO, (char *)&nonBlocking);
  679.  
  680. Return Values
  681. -------------
  682. ioctl returns 0 on most requests, but may return non-zero values 
  683. on success for some operations.  On failure, ioctl returns -1 and 
  684. errno is set as described below.
  685.  
  686. Errors
  687. ------
  688. ENOTSOCK      Invalid descriptor.
  689. EINVAL        Invalid option specified.
  690.  
  691.  
  692. select()
  693. ********
  694.  
  695. Synopsis
  696. --------
  697. #include <sys/types.h>
  698. #include <sys/time.h>
  699.  
  700. int select(int width,long *read,long *write,long *except,
  701.                      struct timeval *timeout);
  702.  
  703. Description
  704. -----------
  705. The select call examines the bitmasks pointed to by 'read', 
  706. 'write' and except and determines the readability and 
  707. writeability of the sockets specified by the bits in the masks.  
  708. Each bit position in the input mask designates the integer value 
  709. of the socket desired for evaluation.
  710.  
  711. The 'width' parameter indicates the range of selectors to be 
  712. examined.
  713.  
  714. The 'timeout' parameter is a pointer to a structure indicating 
  715. the time to wait (block) for the selection to complete.  A NULL 
  716. timeout pointer indicates that the operation should block 
  717. indefinitely until the select completes.  A poll operation can be 
  718. undertaken by passing a pointer to a timeval structure intialized 
  719. to zero.  
  720.  
  721. Although the primary uses of select include determining whether a 
  722. descriptor is readable or writeable, it can also indicate several 
  723. conditions.  A select can be undertaken on a SOCK_STREAM socket 
  724. in a listening state to determine whether a connection is 
  725. available for acceptance.  This test is performed by setting the 
  726. bit corresponding to the socket in the read mask, and determining 
  727. whether it remains set following the call.  An accept call can 
  728. then be issued to retrieve the pending connection.  Additionally, 
  729. select can indicate a dropped connection on a SOCK_STREAM socket 
  730. in a connected state. This check is performed in a manner similar 
  731. to that for a listening socket (described above).  An immediate 
  732. recv operation can then be performed to either retrieve pending 
  733. data or determine the cause of the failure.
  734.  
  735. Return Values
  736. -------------
  737. On success, select returns a non-negative indicator of the number 
  738. of descriptors successfully examined.  A 0 is returned if a 
  739. timeout occured.  On failure, select returns -1 and errno is set 
  740. as described below.
  741.  
  742. Errors
  743. ------
  744. EBADF         One of the descriptors specified in the bitmasks is 
  745.               invalid.
  746.  
  747.  
  748. setsockopt()
  749. ************
  750.  
  751. Synopsis
  752. --------
  753. #include <sys/types.h>
  754. #include <sys/socket.h>
  755.  
  756. int setsockopt(int s,int level,int name,char *val,int len);
  757.  
  758. Description
  759. -----------
  760. This call provided for compatibility only.
  761.  
  762. accept()
  763. ********
  764.  
  765. Synopsis
  766. --------
  767. #include <sys/types.h>
  768. #include <sys/socket.h>
  769.  
  770. int accept(int s,struct sockaddr_in *addr,int *addrLen);
  771.  
  772. Description
  773. -----------
  774. accept examines the listening socket designated by 's' for 
  775. pending connections.  The socket must be of type SOCK_STREAM 
  776. created by a socket call, bound to an address with bind and is 
  777. listening for connections after a listen call.  If a connection 
  778. is available, accept creates a new socket with the properties of 
  779. s and returns it to the caller as the connected socket.  The 
  780. socket designated by 's' is still available to accept further 
  781. connections.  If no connections are available, and the socket is 
  782. marked as non-blocking, an error is returned as described below.  
  783. If the socket is marked as blocking, the call blocks until a 
  784. connection is available.
  785.  
  786. When a valid connection descriptor is returned, the 'addr' 
  787. parameter is filled with the address of the connection partner, 
  788. up to a length specified by the value pointed to by 'addrLen'.  
  789. The value pointed to by 'addrLen' is then updated to reflect the 
  790. actual size of the address.
  791.  
  792. Return Values
  793. -------------
  794. Like socket, accept returns a non-negative descriptor on success.  
  795. On failure, it returns -1 and sets errno as described below.
  796.  
  797. Errors
  798. ------
  799. ENOTSOCK      Invalid descriptor.
  800. EWOULDBLOCK   No connections pending.
  801.  
  802. See Also
  803. --------
  804. accept, socket connect
  805.  
  806. Synopsis
  807. --------
  808. #include <sys/types.h>
  809. #include <sys/socket.h>
  810.  
  811. int connect(int s,struct sockaddr_in *name,int nameLen);
  812.  
  813. Description
  814. -----------
  815. For SOCK_STREAM type sockets, connect attempts to establish a 
  816. connection between the socket specified by 's' and opened with a 
  817. socket call and a destination socket opened with socket, bound to 
  818. the destination address specified by 'name' and listening for 
  819. connection requests.  A SOCK_STREAM socket can only be connected 
  820. once.
  821.  
  822. For SOCK_DGRAM type sockets, connect specifies the destination to 
  823. be used for send requests and the only peer from which datagrams 
  824. can be received.  Provided for convenience, this allows datagram 
  825. sockets to use the recv and send calls in addition to recvfrom 
  826. and sendto. SOCK_DGRAM sockets can connect multiple times and can 
  827. dissolve the current connection by making a call to connect with 
  828. a NULL destination name.
  829.  
  830. Return Values
  831. -------------
  832. connect returns 0 on success, -1 on failure (errno set as 
  833. described below).
  834.  
  835. Errors
  836. ------
  837. ENOTSOCK      Invalid descriptor.
  838. EAFNOSUPPORT  Invalid address family.
  839. EISCONN       Socket is already connected.
  840. EWOULDBLOCK   Processing connect request.
  841. ECONNREFUSED  Connection refused.
  842. EINPROGRESS   Processing connect request.
  843. ETIMEDOUT     Connection establishment timed out without 
  844.               establishing a connection.
  845.  
  846. See Also
  847. --------
  848. socket, accept, listen, select
  849.  
  850.  
  851. listen()
  852. ********
  853.  
  854. Synopsis
  855. --------
  856. #include <sys/types.h>
  857. #include <sys/socket.h>
  858.  
  859. int listen(int s,int backlog);
  860.  
  861. Description
  862. -----------
  863. listen prepares the SOCK_STREAM socket specified by 's', created 
  864. by a socket call and bound to an address with bind, to accept 
  865. connections made by other SOCK_STREAM sockets calls to connect. 
  866. The connection status of the socket may be queried by calls to 
  867. select, and new connections are retrieved by calls to accept. The 
  868. 'backlog' parameter indicates the number of simultaneous pending 
  869. connections that can be queued between accept calls.
  870.  
  871. Return Values
  872. -------------
  873. listen returns 0 on success, -1 on failure (errno set as 
  874. described below).
  875.  
  876. Errors
  877. ------
  878. ENOTSOCK      Invalid descriptor.
  879. ECONNREFUSED  Socket not bound or non-stream.
  880. ENOBUFFS      Insufficient resources.
  881.  
  882. See Also
  883. --------
  884. socket, accept, select, connect
  885.  
  886.  
  887. recv()
  888. ******
  889.  
  890. Synopsis
  891. --------
  892. #include <sys/types.h>
  893. #include <sys/socket.h>
  894.  
  895. int recv(int s,char *buffer,int buffLen,int flags);
  896.  
  897. Description
  898. -----------
  899. recv is used to receive data for a connected socket from it's 
  900. connection peer.  The 'buffer' parameter is filled up to a 
  901. maximum of 'buffLen' bytes.  If the socket is marked as blocking, 
  902. the recv call waits until data is available on the connection.  
  903. If the socket is marked as non-blocking the call returns 
  904. immediately with an error code if no data is available.  This 
  905. call can be made after a call to select to determine the 
  906. readability fo the socket.
  907.  
  908. Notes
  909. -----
  910. The 'flags' parameter is ignored.
  911.  
  912. Return Values
  913. -------------
  914. On success, recv returns a non-negative integer indicating the 
  915. length of the data returned in the 'buffer' parameter.  On 
  916. connection termination, recv returns 0.  On errors, recv returns -
  917. 1 and errno as described below.
  918.  
  919. Errors
  920. ------
  921. ENOTCONN      Connection terminated.
  922. ENOTSOCK      Invalid descriptor or connection failure.
  923. EWOULDBLOCK   No data available.
  924. ESHUTDOWN     Socket shutdown.
  925.  
  926. See Also
  927. --------
  928. send, sendto, recvfrom
  929.  
  930. send()
  931. ******
  932.  
  933. Synopsis
  934. --------
  935. #include <sys/types.h>
  936. #include <sys/socket.h>
  937.  
  938. int send(int s,char *buffer,int buffLen,int flags);
  939.  
  940. Description
  941. -----------
  942. send is used to transmit data for a connected socket to it's 
  943. connection peer.  A maximum number of bytes will be sent 
  944. corresponding to the 'buffLen' parameter.  If the socket is 
  945. marked as blocking, the send call will wait until all data has 
  946. been sent on the connection.  If the socket is marked as non-
  947. blocking, the call returns immediately with an error code if no 
  948. data was sent.  This call can be made after a call to select to 
  949. determine the writeability of the socket.
  950.  
  951. Notes
  952. -----
  953. The 'flags' parameter is ignored.
  954.  
  955. Return Values
  956. -------------
  957. On success, send returns a non-negative integer indicating the 
  958. number of bytes transmitted.  On failure, -1 is returned with 
  959. errno as described below.
  960.  
  961. Errors
  962. ------
  963. ENOTSOCK      Invalid descriptor
  964. EWOULDBLOCK   No send buffer space available.
  965. ENOTCONN      Connection terminated.
  966. ESHUTDOWN     Socket shutdown.
  967.  
  968. See Also
  969. --------
  970. sendto, recv, recvfrom
  971.  
  972.  
  973. getpeername()
  974. *************
  975.  
  976. Synopsis
  977. --------
  978. #include <sys/types.h>
  979. #include <sys\socket.h>
  980.  
  981. int getpeername(int s,struct sockaddr_in *name,int *nameLen);
  982.  
  983. Description
  984. -----------
  985. Retrieves the name of the remote peer connected to the socket 
  986. specified by 's'.  The 'nameLen' parameter is initialized to the 
  987. maximum space available in the 'name' parameter, and is updated 
  988. to reflect the actual length of the name placed into the 'name' 
  989. parameter.
  990.  
  991. Return Values
  992. -------------
  993. getpeername returns 0 on success, -1 on failure (errno as 
  994. described below).
  995.  
  996. Errors
  997. ------
  998. ENOTSOCK      Invalid descriptor.
  999. ENOTCONN      Socket is not connected.
  1000.  
  1001.  
  1002. recvfrom()
  1003. **********
  1004.  
  1005. Synopsis
  1006. --------
  1007. #include <sys/types.h>
  1008. #include <sys/socket.h>
  1009.  
  1010. int recvfrom(int s, char *buffer, int len, int flags, 
  1011.                     struct sockaddr_in *from, int *flen);
  1012.  
  1013.  
  1014. Description
  1015. -----------
  1016. recvfrom is used to receive data for the connected, SOCK_STREAM 
  1017. type socket or for the SOCK_DGRAM socket specified by 's'.   This 
  1018. call is identical to the recv call with the addition that the 
  1019. 'from' parameter is filled with the name of the socket sending 
  1020. the data. The 'flen' parameter is initialized to the maximum size 
  1021. of the buffer pointed to by from and updated to the actual length 
  1022. of the name placed into the from buffer.
  1023.  
  1024. Notes
  1025. -----
  1026. The 'flags' parameter is ignored.
  1027.  
  1028. Return Values
  1029. -------------
  1030. On success, recv returns a non-negative integer indicating the 
  1031. length of the data returned in the 'buffer' parameter.  On 
  1032. connection termination, recv returns 0.  On errors, recv returns -
  1033. 1 and errno as described below.
  1034.  
  1035. Errors
  1036. ------
  1037. ENOTCONN      Connection terminated.
  1038. ENOTSOCK      Invalid descriptor or connection failure.
  1039. EWOULDBLOCK   No data available.
  1040. ESHUTDOWN     Socket shutdown.
  1041.  
  1042. See Also
  1043. --------
  1044. send, sendto, recv
  1045.  
  1046.  
  1047. sendto()
  1048. ********
  1049.  
  1050. Synopsis
  1051. --------
  1052. #include <sys/types.h>
  1053. #include <sys/socket.h>
  1054.  
  1055. int sendto(int s, char *buffer, int len, int flags, 
  1056.                   struct sickaddr_in *to, int tolen);
  1057.  
  1058. Description
  1059. -----------
  1060. sendto is used to transmit data for the connected, SOCK_STREAM 
  1061. type socket or for the SOCK_DGRAM socket specified by 's'.   This 
  1062. call is identical to the send call with the addition that the 
  1063. 'to' parameter indicates the name of the destination socket for 
  1064. SOCK_DGRAM sockets and is ignored for SOCK_STREAM sockets. The 
  1065. 'tolen' parameter is set size of the buffer to be sent.
  1066.  
  1067. Notes
  1068. -----
  1069. The 'flags' parameter is ignored.
  1070.  
  1071. Return Values
  1072. -------------
  1073. On success, send returns a non-negative integer indicating the 
  1074. number of bytes transmitted.  On failure, -1 is returned with 
  1075. errno as described below.
  1076.  
  1077. Errors
  1078. ------
  1079. ENOTSOCK      Invalid descriptor
  1080. EWOULDBLOCK   No send buffer space available.
  1081. ENOTCONN      Connection terminated.
  1082. ESHUTDOWN     Socket shutdown.
  1083.  
  1084. See Also
  1085. --------
  1086. send, recv, recvfrom
  1087.  
  1088.  
  1089. htonl()
  1090. *******
  1091.  
  1092. Synopsis
  1093. --------
  1094. #include <sys/types.h>
  1095. #include <netinet/in.h>
  1096.  
  1097. long htonl(long ibmdd);         /* host to network long  */
  1098. int  htons(int ibmdw);          /* host to network short */
  1099. long ntohl(long netdd);         /* network to host long  */
  1100. int  ntohs(int netdw);        /* network to host short */
  1101.  
  1102. Description
  1103. -----------
  1104. These routines convert 16 and 32 bit quantities between 80x86 
  1105. byte ordering and network byte ordering, and vice-versa.  They 
  1106. are most often used in combination with the SERVICES routines and 
  1107. Internet address routines.
  1108.  
  1109.  
  1110. inet_addr()
  1111. ***********
  1112.  
  1113. Synopsis
  1114. --------
  1115. #include <sys/types.h>
  1116. #include <sys/socket.h>
  1117. #include <netinet/in.h>
  1118. #include <arpa/inet.h>
  1119.  
  1120. long inet_addr(char *addrDesc);
  1121.  
  1122. Description
  1123. -----------
  1124. inet_addr returns the network long integer representation of the 
  1125. Internet '.' notation ASCIIZ string specified by 'addrDesc'.
  1126.  
  1127. Return Values
  1128. -------------
  1129. inet_addr -1 on invalid input string.
  1130.  
  1131.  
  1132. inet_lnaof()
  1133. ************
  1134.  
  1135. Synopsis
  1136. --------
  1137. #include <sys/types.h>
  1138. #include <sys/socket.h>
  1139. #include <netinet/in.h>
  1140. #include <arpa/inet.h>
  1141.  
  1142. long inet_lnaof(long addr);
  1143.  
  1144. Description
  1145. -----------
  1146. Returns the network byte order long integer value representing 
  1147. the local address portion of the Internet address specified by 
  1148. 'addr'.
  1149.  
  1150.  
  1151. inet_makeaddr()
  1152. ***************
  1153.  
  1154. Synopsis
  1155. --------
  1156. #include <sys/types.h>
  1157. #include <sys/socket.h>
  1158. #include <netinet/in.h>
  1159. #include <arpa/inet.h>
  1160.  
  1161. long inet_makeaddr(long net, long lna);
  1162.  
  1163. Description
  1164. -----------
  1165. Combines the network and local address portions specified in 
  1166. network byte order into a single Internet address.
  1167.  
  1168.  
  1169. inet_netof()
  1170. ************
  1171.  
  1172. Synopsis
  1173. --------
  1174. #include <sys/types.h>
  1175. #include <sys/socket.h>
  1176. #include <netinet/in.h>
  1177. #include <arpa/inet.h>
  1178.  
  1179. long inet_netof(long addr);
  1180.  
  1181. Description
  1182. -----------
  1183. Returns the network byte order long integer value representing 
  1184. the network portion of the Internet address specified by 'addr'.
  1185.  
  1186.  
  1187. inet_network()
  1188. **************
  1189.  
  1190. Synopsis
  1191. --------
  1192. #include <sys/types.h>
  1193. #include <sys/socket.h>
  1194. #include <netinet/in.h>
  1195. #include <arpa/inet.h>
  1196.  
  1197. long inet_network(char *cp);
  1198.  
  1199. Description
  1200. -----------
  1201. Converts the Internet '.' notation address specified by 'cp' to 
  1202. an Internet address and returns the network portion of the 
  1203. address.
  1204.  
  1205.  
  1206. inet_ntoa()
  1207. ***********
  1208.  
  1209. Synopsis
  1210. --------
  1211. #include <sys/types.h>
  1212. #include <sys/socket.h>
  1213. #include <netinet/in.h>
  1214. #include <arpa/inet.h>
  1215.  
  1216. char *inet_ntoa(long a); 
  1217.  
  1218. Description
  1219. -----------
  1220. Converts the Internet address specified by 'a' to an Internet '.' 
  1221. notation ASCIIZ string representing the address.
  1222.  
  1223. Notes
  1224. -----
  1225. String is STATIC and will be overwritten with each call.
  1226.  
  1227.  
  1228. setpwent()
  1229. **********
  1230.  
  1231. Synopsis
  1232. --------
  1233. #include <pwd.h>
  1234.  
  1235. void setpwent(void);
  1236.  
  1237. Description
  1238. -----------
  1239. setpwent opens and rewinds the local password file. This call is 
  1240. primarily useful for resetting the password file to the first 
  1241. entry in preparation for calls to getpwent.
  1242.  
  1243.  
  1244. getpwent()
  1245. **********
  1246.  
  1247. Synopsis
  1248. --------
  1249. #include <pwd.h>
  1250.  
  1251. struct passwd *getpwent(void);
  1252.  
  1253. Description
  1254. -----------
  1255. getpwent reads the next entry in the local password file, opening 
  1256. the file if necessary. The return value is a pointer to a 
  1257. structure containing the broken-out fields of an entry from the 
  1258. password information file with the structure definition is as 
  1259. follows:
  1260.  
  1261. struct passwd {
  1262.     char *pw_name;
  1263.     char *pw_passwd;
  1264.     int pw_uid;
  1265.     int pw_gid;
  1266.     int pw_quota;
  1267.     char *pw_comment;
  1268.     char *pw_gecos;
  1269.     char *pw_dir;
  1270.     char *pw_shell;
  1271. };
  1272.  
  1273. pw_name          Official username.
  1274. pw_passwd     Encrypted password for the user.
  1275. pw_uid          Userid for the user.
  1276. pw_gid          Unused at this time.
  1277. pw_quota      Unused at this time.
  1278. pw_comment    Unused at this time.
  1279. pw_gecos      Unused at this time.
  1280. pw_dir          Home directory for the user.
  1281. pw_shell      Unused at this time.
  1282.  
  1283. Return Values
  1284. -------------
  1285. getpwent returns: NULL on failure of EOF.
  1286.  
  1287. See Also
  1288. --------
  1289. getpwuid, getpwnam, setpwent, getlogin, getuid
  1290.  
  1291.  
  1292. getpwuid()
  1293. **********
  1294.  
  1295. Synopsis
  1296. --------
  1297. #include <pwd.h>
  1298.  
  1299. struct passwd *getpwuid(uid_t uid);
  1300.  
  1301. Description
  1302. -----------
  1303. getpwuid searches the password file sequentially for a pw_uid 
  1304. matching that specified by the uid parameter. When a match is 
  1305. found, the corresponding passwd entry is returned.
  1306.  
  1307. Notes
  1308. -----
  1309. The passwd structure is defined in the description for getpwent.
  1310.  
  1311. Return Values
  1312. -------------
  1313. getpwuid returns: NULL on failure.
  1314.  
  1315.  
  1316. getpwnam()
  1317. **********
  1318.  
  1319. Synopsis
  1320. --------
  1321. #include <pwd.h>
  1322.  
  1323. struct passwd *getpwnam(char *name);
  1324.  
  1325. Description
  1326. -----------
  1327. getpwuid searches the password file sequentially for a pw_name 
  1328. matching that specified by the name parameter. When a match is 
  1329. found, the corresponding passwd entry is returned.
  1330.  
  1331. Notes
  1332. -----
  1333. The passwd structure is defined in the description for getpwent.
  1334.  
  1335. Return Values
  1336. -------------
  1337. getpwnam returns: Null on failure.
  1338.  
  1339.  
  1340. getlogin()
  1341. **********
  1342.  
  1343. Synopsis
  1344. --------
  1345. #include <pwd.h>
  1346.  
  1347. char *getlogin(void);
  1348.  
  1349. Description
  1350. -----------
  1351. getlogin returns the username of the current system user.
  1352.  
  1353. Notes
  1354. -----
  1355. Value returned is STATIC and is updated by subsequent calls.
  1356.  
  1357.  
  1358. getuid()
  1359. ********
  1360.  
  1361. Synopsis
  1362. --------
  1363. #include <pwd.h>
  1364.  
  1365. int getuid(void);
  1366.  
  1367. Description
  1368. -----------
  1369. getuid returns the user id of the current system user.
  1370.  
  1371.  
  1372.  
  1373. DESQview/X Extension Routines
  1374. -----------------------------
  1375. In order for an application to use the BSD 4.3 Socket Library, 
  1376. several extension routines are needed. These perform the 
  1377. functions of initializing and terminating the use of the 
  1378. DESQview/X Berkeley Socket Interface. In addition routines are 
  1379. provided to facilitate communication with the Network Manager as 
  1380. a daemon process - see the Network Daemons Programming Reference 
  1381. for additional details and extension routines.
  1382.  
  1383.  
  1384. so_init()
  1385. *********
  1386.  
  1387. Synopsis
  1388. --------
  1389. #include <sys\socket.h>
  1390.  
  1391. int so_init(void);
  1392.  
  1393. Description
  1394. -----------
  1395. so_init is an extension call that initializes the DESQview/X 
  1396. Socket Interface and returns the availabilty of socket resources.
  1397.  
  1398. Notes
  1399. -----
  1400. DESQview/X extension call.
  1401.  
  1402. Return Values
  1403. -------------
  1404. so_init returns 1 on success, 0 on failure.
  1405.  
  1406.  
  1407. so_exit()
  1408. *********
  1409.  
  1410. Synopsis
  1411. --------
  1412. #include <sys\socket.h>
  1413.  
  1414. void so_exit(void);
  1415.  
  1416. Description
  1417. -----------
  1418. Uninitializes the socket interface for the DESQview/X process.
  1419.  
  1420. Notes
  1421. -----
  1422. DESQview/X extension call.
  1423.  
  1424.  
  1425. so_setupdaemon()
  1426. ****************
  1427.  
  1428. Synopsis
  1429. --------
  1430. #include <sys\socket.h>
  1431.  
  1432. void so_setupdaemon(char *name);
  1433.  
  1434. Description
  1435. -----------
  1436. The so_setupdaemon 
  1437. call allows a DESQview/X application to assume the identity of a 
  1438. network daemon.  The 'name' parameter refers to a valid entry in 
  1439. the local SERVICES file.  Following the call, the application can 
  1440. then issue so_daemon calls to check for connections/datagrams - 
  1441. see the section Network Daemons Programming Reference for 
  1442. details.
  1443.  
  1444. Notes
  1445. -----
  1446. DESQview/X extension call.
  1447.  
  1448.  
  1449. getpwvar()
  1450. **********
  1451.  
  1452. Synopsis
  1453. --------
  1454. #include <pwd.h>
  1455.  
  1456. char *getpwvar(char *key, char *var);
  1457.  
  1458. Description
  1459. -----------
  1460. getpwvar returns the ASCIIZ string describing the value indicated 
  1461. by parameters var and key. The key parameter indicates the key 
  1462. into the password information file and usually indicates a 
  1463. username. The var parameter is the variable that has been defined 
  1464. in the password information file to hold the value.
  1465.  
  1466.